import {rest} from 'msw'

const mockPostList = {
    "num_pages": 1,
    "count": 2,
    "results": [
        {
            "id": 1,
            "slug": "dfs33",
            "title": "dfs33",
            "subtitle": "",
            "img_path": "/media/images/beach.jpg",
            "content": "sfdf",
            "excerpt": "sfdf...",
            "pub_date": "2021年10月09日 07:01",
            "category": "其他",
            "tags": [
                "typehint"
            ],
            "num_views": 1
        },
        {
            "id": 2,
            "slug": "5",
            "title": "5",
            "subtitle": "",
            "img_path": "/media/images/di_z5ktXxA.jpeg",
            "content": "5",
            "excerpt": "5...",
            "pub_date": "2021年10月02日 07:48",
            "category": "其他",
            "tags": [
                "react",
                "python"
            ],
            "num_views": 1
        }
    ]
}

const mockSinglePost = {
    "id": 1,
    "slug": "title1",
    "title": "title1",
    "subtitle": "",
    "img_path": "/media/images/beach.jpg",
    "content": "<p>内容</p>",
    "excerpt": "内容...",
    "pub_date": "2021年12月09日 07:01",
    "category": "其他",
    "tags": [
        "typehint"
    ],
    "num_views": 6,
    "next_post": null
}

const mockCategoryPosts = {
    "num_pages": 1,
    "count": 2,
    "results": [
        {
            "title": "python",
            "pub_date": "2021年12月09日 07:01",
            "slug": "python"
        },
        {
            "title": "5",
            "pub_date": "2021年10月02日 07:48",
            "slug": "5"
        }
    ]
}

export const handlers = [
    rest.get('/api/v1/posts/', (req, res, ctx) => {
        return res(ctx.status(200), ctx.json(mockPostList))
    }),
    rest.get('/api/v1/posts/title1/', (req, res, ctx) => {
        return res(ctx.status(200), ctx.json(mockSinglePost))
    }),
    rest.get('/api/v1/posts/archive/2021/10/', (req, res, ctx) => {
        return res(ctx.status(200), ctx.json(mockPostList))
    }),
    rest.get('/api/v1/categories/django/', (req, res, ctx) => {
        return res(ctx.status(200), ctx.json(mockCategoryPosts))
    }),
]